//
//  FlagViewController.m
//  PickerView
//
//  Created by cocoazxj@163.com on 15/4/1.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "FlagViewController.h"
#import "FlagModel.h"
#import "FlagSubView.h"

@interface FlagViewController ()<UIPickerViewDelegate, UIPickerViewDataSource>
@property (nonatomic, strong) IBOutlet UIPickerView *pv_view;
@property (nonatomic, strong) NSArray *mArray;
@end

@implementation FlagViewController

- (NSArray *)mArray
{
    if (!_mArray)
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"flags" ofType:@".plist"];
        NSArray *array = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *m = [NSMutableArray array];
        for(NSDictionary *d in array)
        {
            [m addObject:[FlagModel flagModel:d]];
        }
        _mArray = m;
    }
    return _mArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.mArray.count;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 44;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    FlagSubView *flagView = (FlagSubView *)view;
    if (!flagView)
    {
        flagView = [FlagSubView flagSubView];
    }
    
    flagView.flagM = self.mArray[row];
    NSLog(@"--------------%ld-------------%p",row,view);
    return flagView;
}
@end
